package cn.jslancer.webx;

import cn.jslancer.webx.request.ServerRequest;
import cn.jslancer.webx.rest.RestResponse;
import cn.jslancer.webx.router.Router;
import cn.jslancer.webx.server.Server;

/**
 * @author zhuangchao
 * @date 2018-07-27 18:37
 */
public class ServerTest {

    public static void main(String[] args) {
        Webx webx = Webx.webx();
        Server server = webx.createServer();

        Router router = webx.router();
        router.get("/hi").handler(context -> {
            ServerRequest request = context.request();

            String name = request.getParam("name");

            RestResponse<String> resp = new RestResponse<>();
            resp.setCode(200);
            resp.setMsg("ok");
            resp.setData(name);
            context.json(resp);
        });

        server.registerHandler(router::accept);

        server.listen(8080);
    }
}
